#include"Classbook.h"
#include<algorithm>
#include<string.h>

using namespace std;
using namespace LB;
Classbook::Classbook(int m_cid,char* m_classname)
{
	this->m_cid=m_cid;
	strcpy(this->m_classname,m_classname);
}
Classbook::Classbook(vector<Book> b,const char name[20],int id)
{
	for (unsigned int i = 0; i < b.size(); ++i)
	{
		Book newB(b[i]);
		this->v_book.push_back(newB);
	}
	strcpy(m_classname,name);
	m_cid=id;
}
bool Classbook::findbook(Book& findbook)
{
	vector<Book>::iterator it;
	it=find(v_book.begin(),v_book.end(),findbook);
	if(it!=v_book.end()) 
	{
		findbook = *it;
		cout << "class findbook: " << findbook.v_comment.size() << endl;
		return true;
	}
	else 
	{
		return false;
	}
}
void Classbook::addbook(Book& book)
{
	v_book.push_back(book);
}
void Classbook::deletebook(int bid)
{
	vector<Book>::iterator p=v_book.begin();
	for(unsigned int i=0;i<v_book.size();i++,p++)
	{
		if(bid==v_book[i].m_bid)
		v_book.erase(p);	
	}	
}
void Classbook::listbook(void)
{
	for(unsigned int i=0;i<v_book.size();i++)
	{
		
		
		v_book[i].showbook();
	}
}
void Classbook::sortbooks(void)
{

	sort(v_book.begin(),v_book.end());
}
Book Classbook::highestpraisebook(void)
{
	sortbooks();
	return v_book[0];
}
Book Classbook::mostborrowbook(void)
{
	int maxborrowtimes=v_book[0].borrow_times;
	int j=0;
	for(unsigned int i=0;i<v_book.size();i++)
	{
		if(maxborrowtimes<v_book[i].borrow_times)
		{
			maxborrowtimes=v_book[i].borrow_times;
			j=i;
		}
	}
	return v_book[j];
}